package grex.Nodes;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @authAnd not attributable
 * @version 1.0
 */

import grex.Data.PredictionContainer;

public class And extends Node {
  private static final int NROFCILDREN=2;
  public And(){
    super(NROFCILDREN);
  }

  public synchronized void execute(Node parent,PredictionContainer data,int mode) throws GeneException{
    this.parent = parent;   
    Node[] childs=this.getChildren();
    PredictionContainer lResult = data;
    PredictionContainer rResult = data.clone();
    childs[0].execute(this, lResult, mode);
    childs[1].execute(this, rResult,mode);
    for(double[] key:data.keySet()){
        if(lResult.get(key).getCondition() && rResult.get(key).getCondition())
            data.get(key).setPrediction(1);
        else
            data.get(key).setPrediction(0);
        
    }
  }

  public Object clone() {
    And newAnd = new And();
    newAnd.setOptions(ops);
    cloneChildren(newAnd);
    newAnd.setParent(parent);
    newAnd.environment = environment;
    return newAnd;
  }


  public String toString(){
    return "And";
  }

}
